<template>
  <a-modal
    v-model:open="openDeletePicture"
    title="删除图片"
    ok-text="确定"
    cancel-text="取消"
    @ok="deletePicture"
  >
    <p>你确定要删除该图片？</p>
  </a-modal>
</template>

<script setup lang="ts">

import { ref } from 'vue'
import { message } from 'ant-design-vue'
import { deletePictureUsingPost } from '@/api/pictureController.ts'

const openDeletePicture = ref(false)
let deleteId = ref<number>(0)
// 获取父组件方法
const emit = defineEmits(['refresh'])

// 打开对话框
const openDialog = (id: number) => {
  deleteId.value = id
  openDeletePicture.value = true
}

// 删除图片
const deletePicture = async () => {
  if (!deleteId.value) {
    return
  }
  const res = await deletePictureUsingPost({ id: deleteId.value })
  if (res.data.code === 0 && res.data.data) {
    message.success('删除成功')
    openDeletePicture.value = false
    await emit('refresh')
  } else {
    message.error('删除失败，' + res.data.message)
    openDeletePicture.value = false
  }
}

// 暴露方法
defineExpose({
  openDialog
});

</script>

<style scoped>

</style>
